package dialogos;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import paneles.PanelProductos;
import accesoADatos.AccesoADatos;
import datos.Producto;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ProductoDialog extends javax.swing.JDialog {
	
	private PanelProductos panelProductos;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				ProductoDialog inst = new ProductoDialog(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public ProductoDialog(JFrame frame) {
		super(frame,"Agregar Producto",true);
		initGUI();
	}
	
	public ProductoDialog(JFrame frame, String codigo) {
		super(frame,"Agregar Producto",true);
		initGUI();
		this.panelProductos.setCodigo(codigo);
	}

	private void initGUI() {
		try {
			{
				panelProductos = new PanelProductos();
				getContentPane().add(panelProductos, BorderLayout.CENTER);
				panelProductos.setPreferredSize(new java.awt.Dimension(315, 299));
				panelProductos.getBCancelar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bCancelarActionPerformed(evt);
					}
				});
				panelProductos.getBAceptar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bAceptarActionPerformed(evt);
					}
				});
			}
			pack();
			this.setSize(320, 330);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void bAceptarActionPerformed(ActionEvent evt) {
		Producto p=this.panelProductos.getProducto();
		AccesoADatos.getInstance().setProducto(p);
		this.dispose();
	}
	
	private void bCancelarActionPerformed(ActionEvent evt) {
		this.dispose();
	}

	public void setCodigo(String cod) {
		this.panelProductos.setCodigo(cod);
	}

}
